package com.cn.serverline.lineicp.productionLine.service.impl;

import cn.stylefeng.roses.kernel.office.api.pojo.report.ExcelExportParam;
import cn.stylefeng.roses.kernel.office.excel.OfficeExcel;
import com.alibaba.excel.support.ExcelTypeEnum;
import com.cn.serverline.lineicp.productionLine.constants.RollingPlanConstants;
import com.cn.serverline.lineicp.productionLine.entity.RollingDetails;
import com.cn.serverline.lineicp.productionLine.mapper.RollingDetailsMapper;
import com.cn.serverline.lineicp.productionLine.result.RollingDetailExcelResult;
import com.cn.serverline.lineicp.productionLine.service.IRollingDetailsService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.serverline.lineicp.workshopPlan.entity.request.RollingDetailExcel;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import cn.hutool.core.util.ObjectUtil;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;

import javax.servlet.http.HttpServletResponse;


/**
 * <p>
 * 滚动计划详情 服务实现类
 * </p>
 *
 * @author 郭明然
 * @since 2024-08-22
 */
@Service("RollingDetailsServiceImpl")
@AllArgsConstructor
public class RollingDetailsServiceImpl extends ServiceImpl<RollingDetailsMapper, RollingDetails> implements IRollingDetailsService {

    // Excel 常用操作接口
    private OfficeExcel officeExcel;

    /**
     * 导出模板
     * @author Gmr
     * @param response 响应
     */
    @Override
    public void exportTemplate(HttpServletResponse response) {
        ExcelExportParam excelExportParam = new ExcelExportParam();
        excelExportParam.setClazz(RollingDetailExcelResult.class);
        // 工作簿名称
        excelExportParam.setSheetName(RollingPlanConstants.EXPORT_TEMPLATE_NAME);
        // 下载提示的文件名
        excelExportParam.setFileName(RollingPlanConstants.EXPORT_TEMPLATE_NAME);
        // Excel类型
        excelExportParam.setExcelTypeEnum(ExcelTypeEnum.XLSX);
        excelExportParam.setResponse(response);
        // 下载到浏览器
        officeExcel.easyExportDownload(excelExportParam);
    }

    @Override
    public void add(RollingDetails rollingDetails) {
        this.save(rollingDetails);
    }

    @Override
    public void del(RollingDetails rollingDetails) {
        this.removeById(rollingDetails);
    }

    @Override
    public void edit(RollingDetails rollingDetails) {
        this.updateById(rollingDetails);
    }

    @Override
    public RollingDetails detail(RollingDetails rollingDetails) {
        return this.getById(rollingDetails);
    }

    @Override
    public PageResult<RollingDetails> findPage(RollingDetails rollingDetails) {
        LambdaQueryWrapper<RollingDetails> wrapper = new LambdaQueryWrapper<>();
        // 筛选主要属性
        /* wrapper.select(RollingDetails::getId, RollingDetails::getPositionName, RollingDetails::getCode, RollingDetails::getRemark,
        RollingDetails::getPositionSort, BaseEntity::getCreateTime);*/

        Page<RollingDetails> sysRolePage = this.page(PageFactory.defaultPage(), wrapper);
        return PageResultFactory.createPageResult(sysRolePage);
    }
}
